package com.jin.blog.util;

import java.util.Date;

import org.json.JSONException;

import com.jin.blog.core.BlogConstants;
import com.qiniu.api.auth.AuthException;
import com.qiniu.api.auth.digest.Mac;
import com.qiniu.api.config.Config;
import com.qiniu.api.rs.PutPolicy;

public class Uptoken {

	public static String getToken() throws AuthException, JSONException {
		Mac mac = new Mac(Config.ACCESS_KEY, Config.SECRET_KEY);
		String bucketName = "binarylife";
		PutPolicy putPolicy = new PutPolicy(bucketName);
		putPolicy.saveKey = "$(mimeType)$(year)$(mon)$(day)" + new Date().getTime();
		putPolicy.returnUrl = BlogConstants.DOMAIN + "/ueditor/jsp/QiNiuCallback.jsp";
		putPolicy.returnBody = "{\"name\": $(fname),\"size\": $(fsize),\"type\": $(mimeType),\"key\":$(key)}";
		String token = putPolicy.token(mac);
		return token;
	}
}
